package com.key.util;

import java.text.SimpleDateFormat;

import android.annotation.SuppressLint;
import android.media.MediaRecorder;
import android.media.MediaRecorder.AudioSource;
import android.media.MediaRecorder.OutputFormat;

@SuppressLint("SdCardPath")
public class Listener {

	MediaRecorder mr = new MediaRecorder();
	String strPath = "";
	String strMediaType = "";
	
	public Listener( String _strPath,String _strMideaType ) {
		strPath = _strPath;
		strMediaType = _strMideaType;
	}
	
	void setSavePath( String _strPath ) {
		strPath = _strPath;
	}
	
	void setMediaType( String _strMediaType ) {
		strMediaType = _strMediaType;
	}
	
	public void start() {
		
		SimpleDateFormat sDateFormat = new SimpleDateFormat("yyyyMMddhhmmss");     
		String date = sDateFormat.format(new java.util.Date());  
		
		mr.setAudioSource(AudioSource.MIC);
		mr.setOutputFormat(OutputFormat.THREE_GPP);
		mr.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
		
		String strSavePath = strPath;
		mr.setOutputFile( strSavePath + date + strMediaType); //".amr");
		
		try {
			mr.prepare();
			mr.start();
		} catch(Exception e) {
			e.printStackTrace();
		}
	}
	
	public void end() {
		
		try {
			mr.stop();
			mr.release();
		} catch(Exception e) {
			e.printStackTrace();
		}
	}
	
}
